---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# ccesMRPviz

<!-- badges: start -->
<!-- badges: end -->

The goal of ccesMRPviz is to visualize and diagnose common tasks in MRP and survey analysis. It was formerly a part of the [ccesMRPrun](https://github.com/kuriwaki/ccesMRPrun) package.


```{r, messages=FALSE, warnings=FALSE}
library(dplyr)
library(ccesMRPrun)
library(ccesMRPviz)
```


```{r}
# MRP sims setup
mrp_df <- summ_sims(poststrat_draws(fit_GA, poststrat_tgt = acs_GA)) %>%
  left_join(elec_GA)


mrp_df
```

## scatter_45

Currently, the only function is `scatter_45`, which is a wrapper around ggplot which enforces a visualization of a simple scatterplot that I [argue](https://github.com/RohanAlexander/mrpbook) is important for finding patterns in survey estimates relative to ground truth. These graphs:

- Enforce a 1:1 aspect ratio
- Uses the same range for both axes

which makes the plot into a square.

In addition, this wrapper easily enables:

- Computation and listing of summary stats (RMSE, Correlation, Mean Deviance)
- Facetting scatterplots using `facet_wrap`
- Adding confidence intervals
- Coloring and labeling points.


```{r viz1}
scatter_45(mrp_df,
           clinton_vote,
           p_mrp_est,
           lblvar = cd,
           lbvar = p_mrp_050,
           ubvar = p_mrp_950,
           xlab = "Clinton Vote",
           ylab = "MRP Estimate")

```

